<?php 
include 'config.php';
include 'functions.php';
include './includes/classes/conexao.class.php';
$bd = 'gw';
$conexao = new Conexao($bd); 
/*
 * Função para atualização de níveis hierárquicos nas tabelas;
 */
// $parent is the parent of the children we want to see 
// $level is increased when we go deeper into the tree, 
//        used to display a nice indented tree 
function display_children($parent, $level) { 
   // retrieve all children of $parent 
   $result = pg_query("SELECT id, descricao FROM areas WHERE pai=$parent ORDER BY descricao"); 

   // display each child 
   while ($row = pg_fetch_array($result)) { 
       // indent and display the title of this child 
       echo str_repeat('&nbsp;&nbsp;&nbsp;',$level).$row['descricao']."<br/>"; 

       // call this function again to display this 
       // child's children 
       display_children($row['id'], $level+1); 
   } 
} 

?>
<html>
<head>
<title>Teste</title>
<script type="text/javascript" src="./includes/js/jquery/jquery-1.3.2.min.js"></script>
<!-- Extensão TreeView do jQuery -->
<link rel="stylesheet" type="text/css" href="./includes/js/jquery/ext/treeview/jquery.treeview.css" />
<script src="./includes/js/jquery/ext/treeview/lib/jquery.cookie.js" type="text/javascript"></script>
<script type="text/javascript" charset="utf-8">
function preencheCombo(oq, id) {
	$.ajax({
		type: "GET",
		url: "select.php",
		data: "oq=" + oq + "&id=" + id,
		success: function(txt) {
			$('#cd' + oq).html(txt);
		},
		error: function(txt) {
		}
	});
	//alert(id);
}
</script>
</head>
<body>
<form action="select.php">
	<span style='border:1px solid #000;'>
	<label for='cd_produto_servico' style='width:200px;'>Filiais:
	<select id="cdProdutoServico" name="cd_produto_servico" onchange="preencheCombo('usuarios', this.value);">
		<option value="">Selecione</option>
		<?php 
		$conexao->Executar("SELECT * FROM filiais order by id");
			if($conexao->ContarLinhas() > 0){
				while($line = $conexao->MostrarResultados()){
					echo "<option value='$line[0]'>$line[2]</option>";
				}
			}
		$conexao->Liberar();
		?>
	</select>
	</label>
	</span>
	<select id="cdusuarios" name="cdusuarios" onchange="preencheCombo('sistemas',this.value);">
		<option value="">Selecione um item</option>
	</select>
	<select id="cdsistemas" name="cdsistemas">
		<option value="">Selecione um item</option>
	</select>
	<select id="cdteste" name="cdteste">
		<option value="">Selecione um item</option>
	
	</select>
	
</form>

  
<?php 
  echo $_SERVER['DOCUMENT_ROOT'];
  echo display_children(1,0);
?>
</body> 
</html>